home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE30 / MYDLL.C < prev    next >
C/C++ Source or Header  |  1996-01-02  |  2KB  |  62 lines

  1. #include <windows.h>
  2. #include "mydll.h"
  3.  
  4. // Make this data shared among all 
  5. // all applications that use this DLL.
  6. //....................................
  7. #pragma data_seg( ".GLOBALS" )
  8. int nProcessCount = 0;
  9. int nThreadCount  = 0;
  10. #pragma data_seg()
  11.  
  12. BOOL WINAPI DLLMain( HINSTANCE hInstDLL, DWORD dwNotification, LPVOID lpReserved )
  13. {
  14.     switch(dwNotification)
  15.     {
  16.         case DLL_PROCESS_ATTACH :
  17.                // DLL initialization code goes here. Formerly this 
  18.                // would be in the LibMain function of a 16-bit DLL.
  19.                //..................................................
  20.                nProcessCount++;
  21.                return( TRUE );
  22.  
  23.         case DLL_PROCESS_DETACH :
  24.                // DLL cleanup code goes here. Formerly this would
  25.                // be in the WEP function of a 16-bit DLL.
  26.                //................................................
  27.                nProcessCount--;
  28.                break;                      
  29.  
  30.         case DLL_THREAD_ATTACH :
  31.                // Special initialization code for new threads goes here.
  32.                // This is so the DLL can "Thread Protect" itself.
  33.                //.......................................................
  34.                nThreadCount++;
  35.                break;
  36.  
  37.         case DLL_THREAD_DETACH :
  38.                // Special cleanup code for threads goes here.
  39.                //............................................
  40.                nThreadCount--;
  41.                break;
  42.     }
  43.  
  44.     return( FALSE );
  45. }
  46.  
  47.  
  48. DllAccess int AddNumbers( int a, int b )
  49. {
  50.    return( a + b );
  51. }
  52.  
  53. DllAccess int GetProcessCount()
  54. {
  55.    return( nProcessCount );
  56. }
  57.  
  58. DllAccess int GetThreadCount()
  59. {
  60.    return( nThreadCount );
  61. }
  62.